package com.example.mobile2121606097wjc0509;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private EditText edtTxtMainInput;
    private Button btnMainIE,btnMainCall,btnMainCamera,btnMainRecord;
    private Intent intent;
    private String input;
    private Uri uri;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btnMainIE://浏览器
                input=edtTxtMainInput.getText().toString().trim();
                uri=Uri.parse(input);
                intent= new Intent(Intent.ACTION_VIEW,uri);
                startActivity(intent);
                break;
            case R.id.btnMainCall://拨号码
                input=edtTxtMainInput.getText().toString().trim();
                uri=Uri.parse("tel:"+input);
                intent=new Intent(Intent.ACTION_DIAL,uri);
                startActivity(intent);
                break;
            case R.id.btnMainCamera://相机
                intent=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                startActivity(intent);
                break;
            case R.id.btnMainMap://地图
                input=edtTxtMainInput.getText().toString().trim();
                uri=Uri.parse("geo:"+input);
                intent=new Intent(Intent.ACTION_VIEW,uri);
                startActivity(intent);
                break;
        }
    }

    private void initView() {
        edtTxtMainInput=(EditText) findViewById(R.id.edtTxtMainInput);
        btnMainIE=(Button) findViewById(R.id.btnMainIE);
        btnMainCall=(Button) findViewById(R.id.btnMainCall);
        btnMainCamera=(Button) findViewById(R.id.btnMainCamera);
        btnMainRecord=(Button) findViewById(R.id.btnMainMap);
        btnMainIE.setOnClickListener(this);
        btnMainCall.setOnClickListener(this);
        btnMainCamera.setOnClickListener(this);
        btnMainRecord.setOnClickListener(this);
    }
}